package models.admin;

import models.BaseModel;
import models.admin.enums.BusinessType;
import models.constants.AvailableStatus;

import javax.persistence.*;
import java.util.List;
import java.util.Map;

/**
 * Created by liming on 16/6/29.
 */
@Entity
@Table(name = "admin_business")
public class AdminBusiness extends BaseModel {
    //业务编号
    @Column(name = "code")
    public String code;

    //业务名称
    @Column(name = "name")
    public String name;

    //业务类型
    @Column(name = "business_type")
    @Enumerated(EnumType.STRING)
    public BusinessType businessType;

    @Column(name = "url")
    public String url;

    //业务控制层url
    @Column(name = "controller")
    public String controller;

    /**
     * 主对象
     */
    @Column(name = "main_entity")
    public String mainEntity;

    /**
     * 流水号前缀
     */
    @Column(name = "prefix")
    public String prefix;

    /**
     * 流水号最后日期
     */
    @Column(name = "code_date")
    public String codeDate;

    /**
     * 最大流水号
     */
    @Column(name = "code_num")
    public Integer codeNum;

    /**
     * 流水号长度
     */
    @Column(name = "code_length")
    public Integer codeLength;

    //排序号
    @Column(name = "show_order")
    public Integer showOrder = 0;

    /**
     * 业务流水号是否启用日期
     */
    @Column(name = "code_date_available")
    @Enumerated(EnumType.STRING)
    public AvailableStatus codeDateAvailable;

    @Column(name = "remark")
    public String remark;

    @Column(name = "version")
    public Integer version = 0;

    @Transient
    public List<Map<String, Object>> operateList;

    /**
     * 根据id 删除业务
     *
     * @param id
     */
    public static void deleteById(long id) {
        AdminBusiness.delete("id = ?", id);
    }
}
